package delegate4j;

import com.sun.istack.internal.Nullable;

import java.util.concurrent.FutureTask;

@FunctionalInterface
public interface IAction extends IDelegate {
    void invoke() throws Exception;

    default FutureTask<Void> invokeAsync(@Nullable AsyncCallback callback) {
        FutureTask<Void> futureTask = new FutureTask<>(() -> {
            invoke();
            if (callback != null) {
                callback.invoke(this,null);
            }
            return null;
        });

        ASYNC_DELEGATE_THREAD_POOL.submit(futureTask);
        return futureTask;
    }
}
